%% Functions to plot the ratio of hat-nu and study se by group

function fig = plot_nu_se_ratio(EB_est_nu, rep_base_se2, rep_val_se2)

    N = size(rep_val_se2, 1);
    row_avg = zeros(N,1);
    
    for i = 1:N
        % Variance in each group
        row_vec = [rep_base_se2{i}, rep_val_se2(i)];
        % Compute the mean variance
        row_avg(i) = mean(row_vec);
    end
    
    % Convert variances into se
    row_avg = sqrt(row_avg);

    % Compute the ratios
    ratios = sqrt(EB_est_nu) ./ row_avg;
    [sorted_ratios, ~] = sort(ratios);
    
    % Generate the plot
    fig = figure;
    plot(1:length(ratios), sorted_ratios, 'LineWidth', 2.5);
    hold on;
    yline(1, '--', 'LineWidth', 1.5); % Reference dashed line at y = 1

    xlabel('');
    ylabel('');
    title('');
    set(gca, 'FontSize', 18);
    hold off;

end